var db = require('../middleware/connection.js').db();
var mysql2      = require('mysql');
var db2 = mysql2.createConnection({
		  host     : 'localhost',
		  user     : 'root',
		  password : ''
		});

var mysql3      = require('mysql');
var db3 = mysql3.createConnection({
		  host     : 'localhost',
		  user     : 'root',
		  password : ''
		});



var checkBuildQ = exports.checkBuildQ = function(tick,callback) {
	var sql = "SELECT * FROM browsergame.build_q WHERE build_q.tick = "+tick+"";
	db.query(sql,function(err,result){
		callback(result);
	});
}

var addBuilding = exports.addBuilding = function(building_id,new_build_level,callback) {
	var sql = "UPDATE browsergame.user_buildings SET user_buildings.build_level = new_build_level WHERE build_id = build_id AND player_id = player_id";
	db.query(sql,function(err,result){
		console.log(err);

	});
}

var updateResources = exports.updateResources = function(tick,callback) {
	var sql = "SELECT * FROM browsergame.build_q WHERE build_q.tick = "+tick+"";
	db2.query(sql,function(err,result){
		callback(result);
	});
}

var updateResources3 = exports.updateResources3 = function(tick,callback) {
	var sql = "SELECT * FROM browsergame.build_q WHERE build_q.tick = "+tick+"";
	db3.query(sql,function(err,result){
		callback(result);
	});
}





/*  
	UpdateResources {
		only update resources on action.
	}
Game Loop {
	
	UpdateBuildQ---
 	UpdateAttackQ--


}
*/








